import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { ImagesConst } from "../../resource/ImagesConst";
import { IntimateDescription } from "./item/IntimateDescription";
import { GTextInput } from "../../../../com/mui/controls/GTextInput";
import { GButton } from "../../../../com/mui/controls/GButton";
import { ResFileConst } from "../../resource/ResFileConst";
import { Cache } from "../../cache/Cache";
import { LevelLimitDefin } from "../../../common/defin/LevelLimitDefin";
import { FriendStyle } from "./FriendStyle";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { Global } from "../../../../com/gengine/global/Global";
import { FriendsSearchPlayer } from "./features/FriendsSearchPlayer";
import { KeyCode } from "../../../../com/gengine/keyBoard/KeyCode";
import { PlayerMiniInfo } from "../../model/PlayerMiniInfo";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { BmpToolTipSp } from "./item/BmpToolTipSp";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
//class FriendSelfPart
    
    export  class FriendSelfPart /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            this.createChildren();
            this.addEventListeners();
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc2=null;
            var loc1=ResouceConst.getScaleBitmap("WindowCenterB");
            loc1.setSize(206, 72);
            this._headImageBg = GlobalClass.getBitmap("ItemBg");
            this._headImageBg.width = 38;
            this._headImageBg.height = 38;
            this._headImageBg.x = 3;
            this._headImageBg.y = 4;
            this._headImage = new Object /* flash.display.Bitmap */();
            this._textFieldName = new GTextFiled();
            this._textFieldName.x = 50;
            this._textFieldName.y = 4;
            this._textFieldName.width = 100;
            this._textFieldName.height = 20;
            this._btnHeart = ObjCreate.createGButton(Language.getString(40363), 135, 3, 64, 20);
            loc2 = GlobalClass.getBitmap(ImagesConst.HeartShapedSingle);
            loc2.x = 44;
            loc2.y = 3;
            this._btnHeart.addChild(loc2);
            this._intimateDescription = new IntimateDescription();
            this._intimateDescription.x = 217;
            this._intimateDescription.y = 5;
            this._intimateDescription.visible = false;
            this._textFieldLevel = new GTextFiled();
            this._textFieldLevel.x = 50;
            this._textFieldLevel.y = 25;
            this._textFieldLevel.width = 60;
            this._textFieldLevel.height = 20;
            this._textFieldJob = new GTextFiled();
            this._textFieldJob.x = 120;
            this._textFieldJob.y = 25;
            this._textFieldJob.width = 55;
            this._textFieldJob.height = 20;
            this._textInputSearch = new GTextInput();
            this._textInputSearch.x = 3;
            this._textInputSearch.y = 47;
            this._textInputSearch.width = 150;
            this._textInputSearch.height = 20;
            this._buttonSearch = new GButton();
            this._buttonSearch.x = 155;
            this._buttonSearch.y = 45;
            this._buttonSearch.width = 47;
            this._buttonSearch.height = 22;
            this.addChild(loc1);
            this.addChild(this._headImageBg);
            this.addChild(this._textFieldName);
            this.addChild(this._btnHeart);
            this.addChild(this._intimateDescription);
            this.addChild(this._textFieldLevel);
            this.addChild(this._textFieldJob);
            this.addChild(this._textInputSearch);
            this.addChild(this._buttonSearch);
            this._btnCornucopia = ObjCreate.createGLoadedButton(ResFileConst.cornucopiaBtn, 172, 25, 26, 19, this);
            this._btnCornucopia.toolTipData = "<font color = \'#ffffff\'>" + Language.getString(40364) + "</font>";
            if (Cache.instance.role.entityInfo.level >= LevelLimitDefin.CornucopiaMinLevel) 
            {
                this._btnCornucopia.visible = true;
            }
            else 
            {
                this._btnCornucopia.visible = false;
            }
            this._textFieldName.text = "";
            this._textFieldLevel.text = "";
            this._textFieldJob.text = Language.getString(40365);
            this._textInputSearch.text = Language.getString(40366);
            this._buttonSearch.label = Language.getString(40367);
            this._buttonSearch.styleName = "Button";
            this._textFieldName.setTextFormat(FriendStyle.textFormat1);
            this._textFieldLevel.setTextFormat(FriendStyle.textFormat1);
            this._textFieldJob.setTextFormat(FriendStyle.textFormat1);
            this._textInputSearch.styleName = "GTextInput";
            this._textInputSearch.drawNow();
            this._textInputSearch.setStyle("textFormat", FriendStyle.textFormatOffline);
            this._buttonSearch.label = Language.getString(40367);
            this._buttonSearch.textField.filters = [FilterConst.glowFilter];
            this._textFieldName.filters = [FilterConst.glowFilter];
            this._textFieldLevel.filters = [FilterConst.glowFilter];
            this._textFieldJob.filters = [FilterConst.glowFilter];
            return;
        }

        /* internal  */addEventListeners(): void
        {
            this._textInputSearch.addEventListener(flash.events.FocusEvent.FOCUS_IN, this.changeSearchHandler);
            this._textInputSearch.addEventListener(flash.events.FocusEvent.FOCUS_OUT, this.changeSearchHandler);
            this._textInputSearch.addEventListener(flash.events.KeyboardEvent.KEY_DOWN, this.keboardSearchHandler);
            this._buttonSearch.addEventListener(flash.events.MouseEvent.CLICK, this.btnSearchHandler);
            this._btnHeart.addEventListener(flash.events.MouseEvent.CLICK, this.showIntimateDescription);
            this._btnCornucopia.addEventListener(flash.events.MouseEvent.CLICK, this.showCornucopiaMyInfoHandler);
            return;
        }

        /* internal  */showCornucopiaMyInfoHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CornucopiaShowView));
            return;
        }

        /* internal  */showIntimateDescription(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._intimateDescription.visible = !this._intimateDescription.visible;
            return;
        }

        /* internal  */changeSearchHandler(arg1: Object /* flash.events.FocusEvent */): void
        {
            if (arg1.type == flash.events.FocusEvent.FOCUS_IN && this._textInputSearch.text == Language.getString(40366)) 
            {
                this._textInputSearch.text = "";
            }
            if (arg1.type == flash.events.FocusEvent.FOCUS_OUT && this._textInputSearch.text == "") 
            {
                this._textInputSearch.text = Language.getString(40366);
            }
            return;
        }

        /* internal  */search(): void
        {
            var loc1=this._textInputSearch.text != Language.getString(40366) ? this._textInputSearch.text : "";
            if (this._searchFriend) 
            {
                if (!this._searchFriend.parent) 
                {
                    this._searchFriend.x = (Global.stage.stageWidth - this._searchFriend.width) / 2;
                    this._searchFriend.y = (Global.stage.stageHeight - this._searchFriend.height - 100) / 2;
                    this._searchFriend.show();
                }
                this._searchFriend.search(loc1);
            }
            else 
            {
                this._searchFriend = new FriendsSearchPlayer(loc1);
                this._searchFriend.x = (Global.stage.stageWidth - this._searchFriend.width) / 2;
                this._searchFriend.y = (Global.stage.stageHeight - this._searchFriend.height - 100) / 2;
                this._searchFriend.show();
                this._searchFriend.search(loc1);
            }
            return;
        }

        /* internal  */keboardSearchHandler(arg1: Object /* flash.events.KeyboardEvent */=null): void
        {
            if (arg1.keyCode == KeyCode.ENTER) 
            {
                this.search();
            }
            return;
        }

        /* internal  */btnSearchHandler(arg1: Object /* flash.events.MouseEvent */=null): void
        {
            this.search();
            return;
        }

        public updateName(arg1: string): void
        {
            this._textFieldName.text = arg1;
            this._textFieldName.setTextFormat(FriendStyle.textFormat1);
            return;
        }

        public updateLevel(arg1: string): void
        {
            this._textFieldLevel.text = Language.getString(40368) + arg1;
            this._textFieldLevel.setTextFormat(FriendStyle.textFormat1);
            if (int(arg1) >= LevelLimitDefin.CornucopiaMinLevel) 
            {
                this._btnCornucopia.visible = true;
            }
            else 
            {
                this._btnCornucopia.visible = false;
            }
            return;
        }

        public updateJob(arg1: string): void
        {
            this._textFieldJob.text = arg1;
            this._textFieldJob.setTextFormat(FriendStyle.textFormat1);
            return;
        }

        public updateHeadImage(arg1: Object /* flash.display.Bitmap */): void
        {
            if (this._headImage.parent) 
            {
                this._headImage.parent.removeChild(this._headImage);
            }
            this._headImage = arg1;
            this._headImage.x = 4;
            this._headImage.y = 5;
            this.addChild(this._headImage);
            return;
        }

        public updateSearchResult(arg1: Boolean, arg2: PlayerMiniInfo): void
        {
            if (this._searchFriend) 
            {
                this._searchFriend.showSearchResults(arg1, arg2);
            }
            return;
        }

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_headImage: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_headImageBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_spHeart: BmpToolTipSp;

        /* internal */ /* var */_btnHeart: GButton;

        /* internal */ /* var */_intimateDescription: IntimateDescription;

        /* internal */ /* var */_textFieldName: GTextFiled;

        /* internal */ /* var */_textFieldLevel: GTextFiled;

        /* internal */ /* var */_textFieldJob: GTextFiled;

        /* internal */ /* var */_textInputSearch: GTextInput;

        /* internal */ /* var */_buttonSearch: GButton;

        /* internal */ /* var */_btnCornucopia: GLoadedButton;

        /* internal */ /* var */_searchFriend: FriendsSearchPlayer;
    }
